<?php
namespace app\api\controller;
use think\Lang;
/**
 * ============================================================================
 * DSMall多用户商城
 * ============================================================================
 * 版权所有 2014-2028 长沙德尚网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.csdeshang.com
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * 资金控制器
 */
class Memberfund extends MobileMember {

    public function _initialize() {
        parent::_initialize(); // TODO: Change the autogenerated stub
        Lang::load(APP_PATH . 'home/lang/'.config('default_lang').'/predeposit.lang.php');
    }

    /**
     * @api {POST} api/Memberfund/predepositlog 预存款日志列表
     * @apiVersion 1.0.0
     * @apiGroup MemberFund
     *
     * @apiHeader {String} X-DS-KEY 用户授权token
     *
     * @apiParam {Int} page 页码
     * @apiParam {Int} per_page 每页数量
     * 
     * @apiSuccess {String} code 返回码,10000为成功
     * @apiSuccess {String} message  返回消息
     * @apiSuccess {Object} result  返回数据
     * @apiSuccess {Object[]} result.list  预存款记录列表
     * @apiSuccess {Int} result.list.lg_addtime  记录时间
     * @apiSuccess {String} result.list.lg_addtime_text  记录时间描述
     * @apiSuccess {String} result.list.lg_admin_name  管理员名称
     * @apiSuccess {Float} result.list.lg_av_amount  变更可用金额
     * @apiSuccess {String} result.list.lg_desc  变更描述
     * @apiSuccess {Float} result.list.lg_freeze_amount  变更冻结金额
     * @apiSuccess {Int} result.list.lg_id  记录ID
     * @apiSuccess {Int} result.list.lg_member_id  用户ID
     * @apiSuccess {String} result.list.lg_member_name  用户名称
     * @apiSuccess {String} result.list.lg_type  记录类型
     * @apiSuccess {Int} result.page_total  总页数
     * @apiSuccess {Boolean} result.hasmore  是否有更多 true是false否
     */
    public function predepositlog() {
        $predeposit_model = model('predeposit');
        $where = array();
        $where['lg_member_id'] = $this->member_info['member_id'];
        $where['lg_av_amount'] = array('neq', 0);
        $list = $predeposit_model->getPdLogList($where, $this->pagesize, '*', 'lg_id desc');
        if ($list) {
            foreach ($list as $k => $v) {
                $v['lg_addtime_text'] = @date('Y-m-d H:i:s', $v['lg_addtime']);
                $list[$k] = $v;
            }
        }
        
        $result = array_merge(array('list' => $list), mobile_page($predeposit_model->page_info));
        ds_json_encode(10000, '', $result);
    }

    /**
     * @api {POST} api/Memberfund/rcblog 充值卡余额变更日志
     * @apiVersion 1.0.0
     * @apiGroup MemberFund
     *
     * @apiHeader {String} X-DS-KEY 用户授权token
     *
     * @apiParam {Int} page 页码
     * @apiParam {Int} per_page 每页数量
     * 
     * @apiSuccess {String} code 返回码,10000为成功
     * @apiSuccess {String} message  返回消息
     * @apiSuccess {Object} result  返回数据
     * @apiSuccess {Object[]} result.log_list  充值卡记录列表 （返回字段参考rcblog）
     * @apiSuccess {Int} result.log_list.add_time_text  记录时间
     * @apiSuccess {Int} result.page_total  总页数
     * @apiSuccess {Boolean} result.hasmore  是否有更多 true是false否
     */
    public function rcblog() {
        $rcblog_model = model('rcblog');
        $where = array();
        $where['member_id'] = $this->member_info['member_id'];
        $log_list = $rcblog_model->getRechargecardBalanceLogList($where, $this->pagesize, 'rcblog_id desc');
        if ($log_list) {
            foreach ($log_list as $k => $v) {
                $v['add_time_text'] = @date('Y-m-d H:i:s', $v['rcblog_addtime']);
                $log_list[$k] = $v;
            }
        }
        $result = array_merge(array('log_list' => $log_list), mobile_page($rcblog_model->page_info));
        ds_json_encode(10000, '', $result);
    }


    /**
     * @api {POST} api/Memberfund/pdrechargelist 充值明细
     * @apiVersion 1.0.0
     * @apiGroup MemberFund
     *
     * @apiHeader {String} X-DS-KEY 用户授权token
     *
     * @apiParam {Int} page 页码
     * @apiParam {Int} per_page 每页数量
     *
     * @apiSuccess {String} code 返回码,10000为成功
     * @apiSuccess {String} message  返回消息
     * @apiSuccess {Object} result  返回数据
     * @apiSuccess {Object[]} result.list  充值记录列表
     * @apiSuccess {Int} result.list.pdr_addtime  记录时间
     * @apiSuccess {String} result.list.pdr_addtime_text  记录时间描述
     * @apiSuccess {String} result.list.pdr_admin  管理员名称
     * @apiSuccess {Float} result.list.pdr_amount  充值金额
     * @apiSuccess {Int} result.list.pdr_id  记录ID
     * @apiSuccess {Int} result.list.pdr_member_id  用户ID
     * @apiSuccess {String} result.list.pdr_member_name  用户名称
     * @apiSuccess {String} result.list.pdr_payment_code  支付方式代码
     * @apiSuccess {String} result.list.pdr_payment_name  支付方式名称
     * @apiSuccess {Int} result.list.pdr_payment_state  支付状态
     * @apiSuccess {String} result.list.pdr_payment_state_text  支付状态描述
     * @apiSuccess {Int} result.list.pdr_paymenttime  支付时间
     * @apiSuccess {String} result.list.pdr_sn  支付单号
     * @apiSuccess {String} result.list.pdr_trade_sn  第三方流水号
     * @apiSuccess {Int} result.page_total  总页数
     * @apiSuccess {Boolean} result.hasmore  是否有更多 true是false否
     */
    public function pdrechargelist() {
        $where = array();
        $where['pdr_member_id'] = $this->member_info['member_id'];
        $predeposit_model = model('predeposit');
        $list = $predeposit_model->getPdRechargeList($where, $this->pagesize, '*', 'pdr_id desc');
        if ($list) {
            foreach ($list as $k => $v) {
                $v['pdr_addtime_text'] = @date('Y-m-d H:i:s', $v['pdr_addtime']);
                $v['pdr_payment_name'] = get_order_payment_name($v['pdr_payment_code']);
                $v['pdr_payment_state_text'] = $v['pdr_payment_state'] == 1 ? lang('predeposit_rechargepaysuccess') : lang('predeposit_rechargewaitpaying');
                $list[$k] = $v;
            }
        }
        $result = array_merge(array('list' => $list), mobile_page($predeposit_model->page_info));
        ds_json_encode(10000, '', $result);
    }

    /**
     * @api {POST} api/MemberFund/pdcashlist 提现记录
     * @apiVersion 1.0.0
     * @apiGroup Memberfund
     *
     * @apiHeader {String} X-DS-KEY 用户授权token
     *
     * @apiSuccess {String} code 返回码,10000为成功
     * @apiSuccess {String} message  返回消息
     * @apiSuccess {Object} result  返回数据
     * @apiSuccess {Object[]} result.list  提现记录列表
     * @apiSuccess {Int} result.list.pdc_addtime 记录时间
     * @apiSuccess {String} result.list.pdc_addtime_text 记录时间描述
     * @apiSuccess {Float} result.list.pdc_amount 提现金额
     * @apiSuccess {String} result.list.pdc_bank_name 提现方式名称
     * @apiSuccess {String} result.list.pdc_bank_no 提现账号
     * @apiSuccess {String} result.list.pdc_bank_user 提现账号真实姓名
     * @apiSuccess {Int} result.list.pdc_id 记录ID
     * @apiSuccess {Int} result.list.pdc_member_id 用户ID
     * @apiSuccess {String} result.list.pdc_member_name 用户名称
     * @apiSuccess {String} result.list.pdc_payment_admin 支付管理员
     * @apiSuccess {Int} result.list.pdc_payment_state 支付状态
     * @apiSuccess {String} result.list.pdc_payment_state_text 支付状态描述
     * @apiSuccess {Int} result.list.pdc_payment_time 支付时间
     * @apiSuccess {String} result.list.pdc_payment_time_text 支付时间描述
     * @apiSuccess {String} result.list.pdc_sn 支付单号
     * @apiSuccess {Int} result.page_total  总页数
     * @apiSuccess {Boolean} result.hasmore  是否有更多 true是false否
     */
    public function pdcashlist() {
        $where = array();
        $where['pdc_member_id'] = $this->member_info['member_id'];
        $predeposit_model = model('predeposit');
        $list = $predeposit_model->getPdcashList($where, $this->pagesize, '*', 'pdc_id desc');
        if ($list) {
            foreach ($list as $k => $v) {
                $v['pdc_addtime_text'] = @date('Y-m-d H:i:s', $v['pdc_addtime']);
                $v['pdc_payment_time_text'] = @date('Y-m-d H:i:s', $v['pdc_payment_time']);
                $v['pdc_payment_state_text'] = $v['pdc_payment_state'] == 1 ? lang('predeposit_rechargepaysuccess') : lang('predeposit_rechargewaitpaying');
                $list[$k] = $v;
            }
        }
        
        $result = array_merge(array('list' => $list), mobile_page($predeposit_model->page_info));
        ds_json_encode(10000, '', $result);
    }

    /**
     * @api {POST} api/Memberfund/rechargecard_add 充值卡充值
     * @apiVersion 1.0.0
     * @apiGroup MemberFund
     *
     * @apiHeader {String} X-DS-KEY 用户授权token
     *
     * @apiParam {String} rc_sn 卡号
     * 
     * @apiSuccess {String} code 返回码,10000为成功
     * @apiSuccess {String} message  返回消息
     * @apiSuccess {Object} result  返回数据
     */
    public function rechargecard_add() {
        $rc_sn = trim(input('post.rc_sn'));

        if (!$rc_sn) {
            ds_json_encode(10001,lang('param_error'));
        }
        try{
            $res = model('predeposit')->addRechargecard($rc_sn, array('member_id' => $this->member_info['member_id'], 'member_name' => $this->member_info['member_name']));
            if ($res['message']) {
                ds_json_encode(10001, $res['message']);
            }
        } catch (\Exception $e) {
            ds_json_encode(10001,$e->getMessage());
        }  
        ds_json_encode(10000, lang('predeposit_recharge_success'),1);
            
        
    }

}